package everydayGrade.t3;

import org.junit.jupiter.api.Test;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * @Author: Siantar
 * @Date: 2023-12-08-16:21
 * @Description: 1.0
 */
public class T2008 {
    public long maxTaxiEarnings(int n, int[][] rides) {
        Arrays.sort(rides, (a, b) -> a[1] - b[1]);
        long[] dp = new long[n + 1];
        int j = 0;
        int m = rides.length;
        for (int i = 2; i < n + 1; i++) {
            dp[i] = dp[i - 1];
            while (j < m && i == rides[j][1]) {
                int start = rides[j][0], value = rides[j][2];
                dp[i] = Math.max(dp[i], dp[start] + i - start + value);
                j++;
            }
        }
        return dp[n];
    }

    @Test
    public void test() {
        System.out.println(maxTaxiEarnings(5, new int[][]{{2, 5, 4}, {1, 5, 1}}));
    }
}
